from django.contrib import admin
from .models import *


# Register your models here.
@admin.register(Classify)
class ClassifyAdmin(admin.ModelAdmin):
    list_display = ('id', 'name', 'parent')
    list_display_links = ('id',)
    list_filter = []


@admin.register(Prompt)
class ClassifyAdmin(admin.ModelAdmin):
    list_display = ('id', 'name', 'classify')
    list_display_links = ('id',)
    list_filter = []


@admin.register(NotifyWay)
class NotifyWayAdmin(admin.ModelAdmin):
    list_display = ('id', 'name', 'active', 'config', 'remark')
    list_display_links = ('id',)
    list_filter = []


@admin.register(Template)
class TemplateAdmin(admin.ModelAdmin):
    list_display = ('id', 'name', 'prompt', 'notify_way', 'content')
    list_display_links = ('id',)
    list_filter = []


@admin.register(Task)
class TaskAdmin(admin.ModelAdmin):
    list_display = (
        'id', 'name', 'user', '分类', '通知方式', 'prompt', 'dimension', 'period', 'value', 'active', 'affirm',
        'recent_exec_dt')
    list_display_links = ('id', 'name', 'user', '分类', 'dimension')
    list_filter = ('user', 'dimension', 'active', 'affirm', 'recent_exec_dt')

    def 分类(self, obj):
        return ','.join([item.name for item in obj.classify.all()])

    def 通知方式(self, obj):
        return ','.join([item.name for item in obj.notify_way.all()])
